$(function(){
  $("body").keydown(function(e){
    if(e.keyCode == 13){
      checkLogInfo();
    }
  });
  $("#loginBtn").on("click",function(){
    checkLogInfo();
  })

  function  checkLogInfo(){
    var username = $("#username").val().trim();
    var password = $("#password").val().trim();
    $(".account-content input").on("focus",function(){
      $("#log-error").addClass("hidden");
    });
    if(username === "" || password === ""){
      $("#log-error").html("请输入用户名或密码").removeClass("hidden");
    }else{
      getUserInfo(username,password);
    }
    return false;
  }

  function getUserInfo(username,password){
    $.ajax({
      url: ctx+"/doLogin.do",
      type:"post",
      datatype:"json",
      data:{
        username: username,
        password: password
      },
      success : function (result) {
            if(result.code=="000000"){
                 $("#log-error").addClass("hidden");
                 window.location.href = "/";
            }else{
              $("#log-error").html(result.message).removeClass("hidden");
            }
      },
      complete: function(){
      }
    })
  }
});
